#include "MDPSolver.h"
#include "MREAgent.h"
#include "types.h"


MDPSolver::MDPSolver(MREAgent* a, TFGenerator* tf, RFGeneralizer* rf)
	: MatlabDrawer("planner")
{
	tfGens = tf; 
	rfGens = rf; 
	agent = a; 
	action_number = a->numberOfActions; 
}


void MDPSolver::draw()
{
	const int resolution = 30; //param: how fine do want to discretize when sending to monitor
	int result = 0; 
	matlab::MatlabMatrix<double>& vals = createMeshedDataStructure(resolution, 1, agent);  

	int cntr = 0; 
	Observation tmp = new Observation_type [agent->dimension]; 
	//fill the rest
	for(int i=2; i< agent->dimension; i++)
		tmp[i] = (agent->taskSpec.double_observations[i].max + agent->taskSpec.double_observations[i].min)/2.0; 


	for (int i=0; i< resolution; i++)
	{
		for(int j=0; j< resolution; j++, cntr++)
		{
			tmp[0] = vals(cntr,0); 
			tmp[1] = vals(cntr,1); 

			double ss = 0; 
			double tmpDouble = 0; 
			Observation tmpObs=0; 
			vals(cntr,2) = getStateValue(tmp); 
		}
	}

	delete[] tmp; 
	matlab::MatlabDrawer::drawMeshedValues(vals, "3D"); 
	delete (&vals); 
}
